﻿using ShanNiang.Hosting.Enumerate;
using ShanNiang.Hosting.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShanNiang.Hosting.Common
{
    /// <summary>
    /// Api分页结果
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ApiPageResult<T> : ApiResult<IPageResponse<T>> where T : class
    {
        public ApiPageResult()
        {
            Code = GlobalErrorCode.Ok;
            Data = new PageResponse<T>();
        }
        /// <summary>
        /// 设置数据
        /// </summary>
        /// <param name="data">数据</param>
        public ApiPageResult(IPageResponse<T> data)
        {
            Code = GlobalErrorCode.Ok;
            Data = data;
        }
        /// <summary>
        /// 设置错误代码和消息
        /// </summary>
        /// <param name="code">错误代码</param>
        public ApiPageResult(GlobalErrorCode code) : this(code, code.GetDescription())
        {

        }
        /// <summary>
        /// 设置错误代码和消息
        /// </summary>
        /// <param name="code">错误代码</param>
        /// <param name="errMessage">消息</param>
        public ApiPageResult(GlobalErrorCode code, string? errMessage) : this(code, errMessage, new PageResponse<T>())
        {

        }
        /// <summary>
        /// 设置错误代码、消息及数据
        /// </summary>
        /// <param name="code">错误代码</param>
        /// <param name="errMessage">消息</param>
        /// <param name="data">数据</param>
        public ApiPageResult(GlobalErrorCode code, string? errMessage, IPageResponse<T> data)
        {
            Code = code;
            ErroMessage = errMessage;
            Data = data;
        }
    }
}
